// pages/person/enter.js
const wh = require("../../utils/wh.js");
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time:'营业开始时间',
    times:'营业结束时间',
  },
  bindTimeChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  bindTimeChanges: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      times: e.detail.value
    })
  },
  formSubmit: function (e) {
    console.log(e.detail.value)
    console.log(e.detail)
    let that = this;
    let shopinfo = e.detail.value;
    if (!shopinfo.shop_name) {
      wx.showToast({
        title: '商户名称不能为空',
        icon: "none"
      })
      return false;
    } else if (!shopinfo.tell) {
      wx.showToast({
        title: '门店电话不能为空',
        icon: "none"
      })
      return false;
    } else if (!shopinfo.address){
      wx.showToast({
        title: '地址不能为空',
        icon: "none"
      })
      return false;
    } else if (!shopinfo.contact){
      wx.showToast({
        title: '联系人不能为空',
        icon: "none"
      })
      return false;
    } else if (!shopinfo.phone){
      wx.showToast({
        title: '联系人手机号不能为空',
        icon: "none"
      })
      return false;
    }
    if (!(/^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(shopinfo.tell))) {
      wx.showToast({
        title: '门店电话格式错误',
        icon: "none"
      })
      return false;
    }
    if (!(/^1[34578]\d{9}$/.test(shopinfo.phone))) {
      wx.showToast({
        title: '手机号格式错误',
        icon: "none"
      })
      return false;
    }
    wh.Post('/api/mall.shop/open', {
      shop_name: shopinfo.shop_name,
      mobile: shopinfo.phone,
      address: shopinfo.address,
      start:this.data.time,
      end:this.data.times,
      shop_cost: shopinfo.shop_cost,
      tell: shopinfo.tell,
      contact: shopinfo.contact,
      form_id: e.detail.formId
    },function(){
      wx.showModal({
        title: '',
        content: '提交成功，请等待审核结果',
        showCancel: false,
        cancelText: '',
        cancelColor: '',
        confirmText: '确定',
        confirmColor: '',
        success: function (res) {
          wx.switchTab({
            url: '../person/person'
          })},
        fail: function(res) {},
        complete: function(res) {
          
        },
      })
      // wx.showToast({
      //   title: '提交成功，请等待审核结果',
      //   complete: function () {
      //     setTimeout(function () {
      //       wx.switchTab({
      //         url: '../person/person'
      //       })
      //     }, 2000);
      //   }
      // })

      return;
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})